<?php

class OrdCommentController extends BaseController
{

	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		//操作ID号格式处理
		if(isset($_GET['id'])){
			$id = $_GET['id'];
		}elseif(isset($_POST['ids'])){
			$id =$_POST['ids'];
		}else{
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
		}
		$id = is_array($id)?join(',',$id):(int)$id;
		//处理条件
		$criteria=new CDbCriteria;
		$criteria->addCondition("zoc_id in ($id)");
		//修改内容
		$set = array('zoc_view'=>'2');//是否隐藏  1否2是 （管理员功能）',
		//执行操作
		if(OrdComment::model()->updateAll($set,$criteria)){
			//成功跳转
			$this->redirect(Yii::app()->request->urlReferrer);
		}
	}


	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new Company('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['Company']))
			$model->attributes=$_GET['Company'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}

	//评价管理
	public function actionComment($id){
		$model=new OrdComment('search');
		$model->unsetAttributes();  // clear any default values
		$model->zoc_type = 2;
		$model->zoc_view = 1;
		$model->zm_id = $id;
		//统计
		$commentInfo = OrdComment::model()->getAmountOfLevels($id,2);
		//平均值
		$commentAvg =  OrdComment::model()->getCmpAvg($id);
		//店铺信息
		$company = Company::model()->findByPk($id);
		if(isset($_GET['OrdComment']))
			$model->attributes=$_GET['OrdComment'];
		
		$this->render('comment',array(
				'model'=>$model,
				'commentInfo'=>$commentInfo,
				'commentAvg'=>$commentAvg,
				'company'=>$company,
		));
	}
}
